package com.adbj.cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CasTest {
    public static void main(String[] args) {
        AtomicInteger atomicInteger=new AtomicInteger(5);

        //和5比较,设置为10
                System.out.println("预期值:5,当前值:"+atomicInteger);
                 System.out.println("是否设置成功:"+atomicInteger.compareAndSet(5, 10));
                 //和5比较,设置为15
                 System.out.println("预期值:5,当前值:"+atomicInteger);
                 System.out.println("是否设置成功:"+atomicInteger.compareAndSet(5, 15));

                System.out.println("当前值:"+atomicInteger);
    }
}
